package com.yfl.logistics.controller;

import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.UnknownAccountException;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/admin")
public class LoginController {


    @GetMapping("/loginPage")
    public String login(){

        return "login";
    }
    @RequestMapping("/login")
    public String loginerr(HttpServletRequest request, Model m){
        //验证失败返回的验证信息
        String shiroLoginFailure = (String) request.getAttribute("shiroLoginFailure");
        //强制访问返回null
        if(StringUtils.isNotBlank(shiroLoginFailure)){
            if (UnknownAccountException.class.getName().equals(shiroLoginFailure)){
                m.addAttribute("errMsg","您的账号不正确");
            }else if (IncorrectCredentialsException.class.getName().equals(shiroLoginFailure)){
                m.addAttribute("errMsg","您的密码错误");
            }
        }

        return "login";
    }

}
